// 文件：controllers/tagController.js
const tagService = require("../services/tagService");
const { successResponse, errorResponse } = require("../utils/response");

// 获取所有标签
exports.getAllTags = async (ctx) => {
  try {
    const tags = await tagService.getAllTags();
    ctx.body = successResponse(tags, "获取所有标签成功");
  } catch (error) {
    ctx.body = errorResponse(error);
  }
};

// 获取单个标签通过id
exports.getTagById = async (ctx) => {
  try {
    const tag = await tagService.getTagById(ctx.params.id);
    ctx.body = successResponse(tag, "获取标签成功");
  } catch (error) {
    ctx.body = errorResponse(error);
  }
};

// 创建新的标签
exports.createTag = async (ctx) => {
  try {
    const tag = await tagService.createTag(ctx.request.body);
    ctx.body = successResponse(tag, "创建标签成功");
  } catch (error) {
    ctx.body = errorResponse(error);
  }
};

// 更新标签
exports.updateTag = async (ctx) => {
  try {
    const tag = await tagService.updateTag(ctx.params.id, ctx.request.body);
    ctx.body = successResponse(tag, "更新标签成功");
  } catch (error) {
    ctx.body = errorResponse(error);
  }
};

// 删除标签
exports.deleteTag = async (ctx) => {
  try {
    await tagService.deleteTag(ctx.params.id);
    ctx.body = successResponse(true, "删除标签成功");
  } catch (error) {
    ctx.body = errorResponse(error);
  }
};
